<template>
  <div class="page">
    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form
        :inline="true"
        size="small"
        :model="formInline"
        class="search_form"
      >
        <el-form-item label="关键词：">
          <el-input v-model="formInline.key" placeholder="城市"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="getList">筛选</el-button>
        <el-button type="default" size="small" @click="rest"
          >清空筛选</el-button
        >
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <!-- 操作区域 开始 -->
      <div class="action_box">
        <el-button type="primary" size="small" @click="add()"
          >新增城市</el-button
        >
      </div>
      <!-- 操作区域 end -->

      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="cityName" label="城市名称" />
        <el-table-column
          prop="sortTime"
          label="排序时间"
          show-overflow-tooltip
        />
        <el-table-column
          prop="isPublished"
          label="是否上架"
          show-overflow-tooltip
        >
          <template slot-scope="{ row }">{{
            row.isPublished ? "是" : "否"
          }}</template>
        </el-table-column>
        <el-table-column
          prop="isFeatured"
          label="是否上首页"
          show-overflow-tooltip
        >
          <template slot-scope="{ row }">{{
            row.isFeatured ? "是" : "否"
          }}</template>
        </el-table-column>
        <el-table-column
          prop="address"
          label="操作"
          width="200px"
          align="center"
        >
          <template slot-scope="{ row }">
            <el-link
              type="primary"
              class="el_link"
              :underline="false"
              :id="row.id"
              @click="add(row.id)"
              >编辑</el-link
            >
            <el-link
              type="danger"
              class="el_link"
              :underline="false"
              :id="row.id"
              @click="remove(row)"
              >删除</el-link
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination_list">
        <el-pagination
          background
          layout="sizes, total,prev, pager, next, jumper"
          :total="pageTotal"
          :page-size="pageSize"
          :page-sizes="pageSizes"
          :current-page.sync="pageNumber"
          @current-change="getList"
          @size-change="changePageSize"
        />
      </div>
    </div>
    <!-- 表格 end -->

    <!-- 新增、编辑城市弹框 开始 -->
    <add-city v-model="showDialog" v-if="showDialog" :id="cityId" @change="getList" />
    <!-- 新增、编辑城市弹框 end -->
  </div>
</template>
    
<script>
import { showToast, showModal, deepClone } from "@/common/util";
import { GET_CITY_LIST, DELETE_CITY_INFO } from "@/http/interface";
import AddCity from "./addCity.vue";
export default {
  components: {
    AddCity,
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 50, 100],
      pageSize: 20,
      orderTime: [],
      loading: false,
      showDialog: false,
      cityId: "",
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = {};
      this.orderTime = [];
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let oParams = JSON.parse(JSON.stringify(this.formInline));

      oParams.current = this.pageNumber;
      oParams.size = this.pageSize;
      return oParams;
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GET_CITY_LIST(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.records || [];
        _this.pageTotal = obj.total;
      });
    },

    // 新增
    add(id) {
      this.showDialog = true;
      this.cityId = id || "";
    },

    // 删除医生
    remove(row) {
      let _this = this;
      showModal({
        message: `确认删除${row.cityName}城市吗？`,
        showCancelButton: true,
        success: function () {
          let oParams = {};
          oParams.id = row.id;
          DELETE_CITY_INFO(oParams).then((res) => {
            if (res.code == 200) {
              showToast({
                message: "删除成功",
                type: "success",
              });
              _this.getList();
            }
          });
        },
      });
    },
  },
};
</script>
    
<style lang="scss" scoped>
@import "@/assets/style/customer/index.scss";
</style>
    